/* START 1a_rawTripCounts.do */

/* INCLUDED AS FILE IN 1_tripCountsByDayAroundOpening.do */

set scheme s2color

fv default

local restat_line_patterns solid shortdash dash shortdash_dot

frame put oa CCK gCCK tripDate TKT_TYP_CD, into(aggcck)
fv aggcck
preserve
gcollapse (count) trips = oa, by(CCK tripDate)

/* RAW (LOG) TRIP COUNTS */
gen logTrips = log(trips)

twoway (scatter logTrips tripDate if CCK == 0, connect(J)) ///
  (scatter logTrips tripDate if CCK == 1, connect(J)), ///
  xline(20449) ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  title("Trip counts by day by CCK subzone group") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  legend(order(1 "All other subzones" ///
  2 "Gombak, Hillview, Jelebu") rows(2))

/* TRIP COUNTS: CCK vs. NOT CCK */
gegen tripRef = mean(trips) if tripDate == td(01dec2015), by(CCK)
fillmissing tripRef, by(CCK)
gen normTrips = trips/tripRef
twoway (scatter normTrips tripDate if CCK == 0, connect(J)) ///
  (scatter normTrips tripDate if CCK == 1, connect(J)), ///
  xline(20449, lcolor(green) lpattern(dash))  ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  title("Scaled trip counts by day, to/from CCK or not") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  legend(order(1 "All other trips (Dec 1: 4.38m)" ///
  2 "To/From Gombak, Hillview, Jelebu (Dec 1: 52.1k)") rows(2))
graph export "${make_data}/aggNormTripsToFromCCK2015.png", replace width(1920)

restore

/* TRIP COUNTS BY ORIGIN/DESTINATION */
preserve
gcollapse (count) trips = oa, by(gCCK tripDate)
gen logTrips = log(trips)
sepscatter logTrips tripDate, separate(gCCK) recast(connect) ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  title("Log trip counts by day, to/from CCK or not") ///
  xtitle("Date") ytitle("Log trip count") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "All other trips" ///
  2 "Trips starting outside but ending in CCK" ///
  3 "Trips starting in CCK but ending outside" ///
  4 "Trips starting and ending in CCK") rows(4))
graph export "${make_data}/aggODTripsCCK2015.png", replace width(1920)

gegen tripRef = mean(trips) if tripDate == td(01dec2015), by(gCCK)
fillmissing tripRef, by(gCCK)
gen normTrips = trips/tripRef
sepscatter normTrips tripDate, separate(gCCK) recast(connect) ///
  msize(tiny tiny tiny tiny) ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  title("Scaled trip counts by day, to/from CCK or not") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "All other trips (Dec 1: 4.38m)" ///
  2 "Trips starting outside but ending in CCK (Dec 1: 26.0k)" ///
  3 "Trips starting in CCK but ending outside (Dec 1: 24.0k)" ///
  4 "Trips starting and ending in CCK (Dec 1: 2.14k)") rows(4))
graph export "${make_data}/aggNormODTripsCCK2015.png", replace width(1920)
restore

/* TRIP COUNTS BY BY CARD TYPE */
preserve
gcollapse (count) trips = oa, by(CCK tripDate TKT_TYP_CD)
gegen grp = group(TKT_TYP_CD CCK)

gen logTrips = log(trips)
/* raw numbers */
sepscatter logTrips tripDate if TKT_TYP_CD == 34 | TKT_TYP_CD == 38, ///
  separate(grp) recast(line)

gegen tripRef = mean(trips) if tripDate == td(01dec2015), by(grp)
fillmissing tripRef, by(grp)
gen normTrips = trips/tripRef
sepscatter normTrips tripDate if TKT_TYP_CD == 34 | TKT_TYP_CD == 38, ///
  separate(grp) recast(line) xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  lpattern(`restat_line_patterns') ///
  title("Change in Trips: Choa Chu Kang") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "High income, outside Choa Chu Kang" /* (Dec 1: 2.67m) */ ///
  2 "High income, to/from/within Choa Chu Kang" /* (Dec 1: 28.8k) */ ///
  3 "Low income, outside Choa Chu Kang" /* (Dec 1: 198.2k) */ ///
  4 "Low income, to/from/within Choa Chu Kang" /* (Dec 1: 2.72k) */) rows(4))
graph save "${dropbox}/norm3438TripsCCK2015.gph", replace
graph export "${dropbox}/norm3438TripsCCK2015.pdf", replace

/* graph export "${make_data}/norm3438TripsCCK2015.png", replace width(1920) */


/*
sepscatter normTrips tripDate if TKT_TYP_CD == 38 | TKT_TYP_CD == 40, ///
  separate(grp) recast(line) xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  lpattern(solid shortdash solid shortdash) ///
  title("Scaled trip counts by day by card type," "to/from CCK or not") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Subsidized worker trips outside CCK (Dec 1: 198.2k)" ///
  2 "Subsidized worker trips to/from/within CCK (Dec 1: 2.72k)" ///
  3 "Elementary school student trips outside CCK (Dec 1: 78.9k)" ///
  4 "Elementary school student trips to/from/within CCK (Dec 1: 1.15k)") rows(4))
graph export "${make_data}/norm3840TripsCCK2015.png", replace width(1920)


sepscatter normTrips tripDate if TKT_TYP_CD >= 40 & TKT_TYP_CD <= 42, ///
  separate(grp) recast(line) xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  lpattern(solid shortdash solid shortdash solid shortdash) ///
  title("Scaled student trip counts by day by card type," "to/from CCK or not") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Elementary school, outside CCK (Dec 1: 78.9k)" ///
  2 "Elementary school, to/from/within CCK (Dec 1: 1.15k)" ///
  3 "Middle school, outside CCK (Dec 1: 191k)" ///
  4 "Middle school, to/from/within CCK (Dec 1: 3.37k)" ///
  5 "Tertiary, outside CCK (Dec 1: 63.4k)" ///
  6 "Tertiary, to/from/within CCK (Dec 1: 856)") rows(6))
graph export "${make_data}/norm40-42TripsCCK2015.png", replace width(1920)
*/
restore

fv default
cap frame drop aggcck

/* BENCHMARKS FOR BEAUTY WORLD */


frame put oa bw gbw tripDate TKT_TYP_CD, into(aggbw)
fv aggbw
preserve
gcollapse (count) trips = oa, by(bw tripDate TKT_TYP_CD)
gegen grp = group(TKT_TYP_CD bw)

gen logTrips = log(trips)
/* raw numbers */
/*
sepscatter logTrips tripDate if TKT_TYP_CD == 34 | TKT_TYP_CD == 38, ///
  separate(grp) recast(line)
*/
gegen tripRef = mean(trips) if tripDate == td(01dec2015), by(grp)
fillmissing tripRef, by(grp)
gen normTrips = trips/tripRef
/*
sepscatter logTrips tripDate if (TKT_TYP_CD == 34 | TKT_TYP_CD == 38), ///
  separate(grp) recast(line) ///
  lpattern(solid shortdash solid shortdash) ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Adult, outside BW" ///
  2 "Workfare, outside BW" ///
  3 "Adult, to/from/within BW" ///  
  4 "Workfare, to/from/within BW" ///
  ) rows(4))
*/

sepscatter normTrips tripDate if (TKT_TYP_CD == 34 | TKT_TYP_CD == 38), ///
  separate(grp) recast(line) ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  lpattern(`restat_line_patterns') ///
  title("Change in Trips: Upper Bukit Timah") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "High income, outside Upper Bukit Timah" /*  (Dec 1: 2.68m) */ ///
  2 "High income, to/from/within Upper Bukit Timah" /*  (Dec 1: 20.0k) */ ///  
  3 "Low income, outside Upper Bukit Timah" /* (Dec 1: 200k) */ ///
  4 "Low income, to/from/within Upper Bukit Timah" /*  (Dec 1: 865) */ ///
  ) rows(4))

graph save "${dropbox}/norm3438TripsBW2015.gph", replace
graph export "${dropbox}/norm3438TripsBW2015.pdf", replace
cap restore

fv default
cap frame drop aggbw


/* OTHER END: DOWNTOWN CORE */
/*
preserve
gcollapse (count) oa, by(downtown tripDate TKT_TYP_CD)
ren oa trips
gen logTrips = log(trips)
gegen grp = group(TKT_TYP_CD downtown)
gegen tripRef = mean(trips) if tripDate == td(01dec2015), by(grp)
fillmissing tripRef, by(grp)
gen normTrips = trips/tripRef
sepscatter logTrips tripDate if (TKT_TYP_CD == 34 | TKT_TYP_CD == 38), ///
  separate(grp) recast(line) ///
  lpattern(solid shortdash solid shortdash) ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Adult, outside Downtown" ///
  2 "Workfare, outside Downtown" ///
  3 "Adult, to/from/within Downtown" ///  
  4 "Workfare, to/from/within Downtown" ///
  ) rows(4))

sepscatter normTrips tripDate if (TKT_TYP_CD == 34 | TKT_TYP_CD == 38), ///
  separate(grp) recast(line) ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  lpattern(solid solid shortdash shortdash) ///
  title("Scaled trip counts by day by card type," "to/from Downtown or not") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Adult, outside Downtown (Dec 1: 2.22m)" ///
  2 "Adult, to/from/within Downtown (Dec 1: 478k)" ///  
  3 "Workfare, outside Downtown (Dec 1: 184k)" ///
  4 "Workfare, to/from/within Downtown (Dec 1: 16.2k)" ///
  ) rows(4))
graph export "${make_data}/norm3438TripsDowntown2015.png", replace width(1920)

/* CONTROL GROUP: GEYLANG */
preserve
gcollapse (count) oa, by(geylang tripDate TKT_TYP_CD)
ren oa trips
gen logTrips = log(trips)
gegen grp = group(TKT_TYP_CD geylang)
gegen tripRef = mean(trips) if tripDate == td(01dec2015), by(grp)
fillmissing tripRef, by(grp)
gen normTrips = trips/tripRef
sepscatter logTrips tripDate if (TKT_TYP_CD == 34 | TKT_TYP_CD == 38), ///
  separate(grp) recast(line) ///
  lpattern(solid shortdash solid shortdash) ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Adult, outside Geylang" ///
  2 "Workfare, outside Geylang" ///
  3 "Adult, to/from/within Geylang" ///  
  4 "Workfare, to/from/within Geylang" ///
  ) rows(4))

sepscatter normTrips tripDate if (TKT_TYP_CD == 34 | TKT_TYP_CD == 38), ///
  separate(grp) recast(line) ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  lpattern(solid solid shortdash shortdash) ///
  title("Scaled trip counts by day by card type," "to/from Geylang or not") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Adult, outside Geylang (Dec 1: 2.47m)" ///
  2 "Adult, to/from/within Geylang (Dec 1: 233k)" ///  
  3 "Workfare, outside Geylang (Dec 1: 184k)" ///
  4 "Workfare, to/from/within Geylang (Dec 1: 17.1k)" ///
  ) rows(4))
graph export "${make_data}/norm3438TripsGeylang2015.png", replace width(1920)
restore
*/

/* ROBUSTNESS: ALL OF DTL2 */
frame put oa nearDTL tripDate TKT_TYP_CD, into(dtl)
fv dtl
/*
preserve
gcollapse (count) trips = oa, by(nearDTL tripDate)
gegen tripRef = mean(trips) if tripDate == td(01dec2015), by(nearDTL)
fillmissing tripRef, by(nearDTL)
gen normTrips = trips/tripRef
sepscatter normTrips tripDate, separate(nearDTL) recast(connect) ///
  lpattern(solid shortdash) ///
  xline(20449, lcolor(green) lpattern(dash))  ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  title("Scaled trip counts by day, to/from DTL2 subzones or not") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  legend(order(1 "All other trips (Dec 1: 4.08m)" ///
  2 "To/From DTL2 subzones (Dec 1: 346.9k)") rows(2))
graph export "${make_data}/aggNormTripsToFromDTL22015.png", replace width(1920)
restore
*/

preserve
gcollapse (count) trips = oa, by(nearDTL tripDate TKT_TYP_CD)
gen logTrips = log(trips)
gegen grp = group(TKT_TYP_CD nearDTL)
gegen tripRef = mean(trips) if tripDate == td(01dec2015), by(grp)
fillmissing tripRef, by(grp)
gen normTrips = trips/tripRef
/*
sepscatter logTrips tripDate if (TKT_TYP_CD == 34 | TKT_TYP_CD == 38), ///
  separate(grp) recast(line) ///
  lpattern(solid shortdash solid shortdash) ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Adult, outside DTL2 subzones" ///
  2 "Workfare, outside DTL2 subzones" ///
  3 "Adult, to/from/within DTL2 subzones" ///  
  4 "Workfare, to/from/within DTL2 subzones" ///
  ) rows(4))
*/

sepscatter normTrips tripDate if (TKT_TYP_CD == 34 | TKT_TYP_CD == 38), ///
  separate(grp) recast(line) ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  lpattern(`restat_line_patterns') ///
  title("Change in Trips: Downtown Line Subzones") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "High income, outside DTL2 subzones" /* (Dec 1: 2.46m) */ ///
  2 "High income, to/from/within DTL2 subzones" /*  (Dec 1: 234k) */ ///  
  3 "Low income, outside DTL2 subzones" /* (Dec 1: 190k) */ ///
  4 "Low income, to/from/within DTL2 subzones" /* (Dec 1: 11.1k) */ ///
  ) rows(4))
  
graph save "${dropbox}/norm3438TripsDTL22015.gph", replace
graph export "${dropbox}/norm3438TripsDTL22015.pdf", replace

/*
sepscatter normTrips tripDate if (TKT_TYP_CD >= 40 & TKT_TYP_CD <= 42), ///
  separate(grp) recast(line) ///
  xlabel(#4, labsize(vsmall)) ylabel(, labsize(vsmall)) ///
  lpattern(solid solid shortdash shortdash dash_dot dash_dot) ///
  title("Scaled trip counts by day by student card type," ///
  "to/from DTL2 subzones or not") ///
  xtitle("Date") ytitle("Trip count (rel. Dec 1 2015)") ///
  xline(20449, lcolor(purple) lpattern(dash)) ///
  legend(order(1 "Elem., outside DTL2 subzones (Dec 1: 2.46m)" ///
  2 "Elem., to/from/within DTL2 subzones (Dec 1: 234k)" ///  
  3 "Sec., outside DTL2 subzones (Dec 1: 190k)" ///
  4 "Sec., to/from/within DTL2 subzones (Dec 1: 11.1k)" ///
  5 "Tert., outside DTL2 subzones (Dec 1: 190k)" ///
  6 "Tert., to/from/within DTL2 subzones (Dec 1: 11.1k)" ///
  ) rows(3))
graph export "${make_data}/norm40-42TripsDTL22015.png", replace width(1920)
*/

cap restore

fv default
cap frames drop dtl


